using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace ProtocToCSharp
{
    public class ArgModel : ArgDictionary<ArgModel>
    {
        

        [ArgObject("--root_path")]
        public DirectoryInfo RootPath { get; set; } = new DirectoryInfo(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase);
        [ArgObject("--build_exe")]

        public FileInfo BuildertPath { get; set; } = new FileInfo(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "protoc.exe");
        [ArgObject("--out_path")]
        public DirectoryInfo OutPath { get; set; } 
        [ArgObject("--run_exit")]
        public bool AutoExit { get; set; } = true;

        [ArgObject("--debug")]
        public bool IsDebug { get; set; } = false;

        public ArgModel(string[] args):base( "=", args)
        {
        }

        public void Debug(string text)
        {
            if (IsDebug)
            {
                Console.WriteLine(text);
            }
        }

        public bool Check()
        {
            if (RootPath==null || BuildertPath==null || OutPath ==null)
            {
                Console.WriteLine("路径格式不正确");
                return false;
            }

            if (!RootPath.Exists)
            {
                Console.WriteLine("根目录路径不正确");
                return false;
            }

            if (!BuildertPath.Exists)
            {
                Console.WriteLine("Protoc编译器路径不正确");
                return false;
            }

            try
            {
                OutPath.Create();
            }
            catch (Exception)
            {


            }

            if (!OutPath.Exists)
            {
                Console.WriteLine("输出目录路径不正确");
                return false;
            }
      
             OutPath = OutPath == null ? new DirectoryInfo(RootPath.FullName) : OutPath;



            return true;
        }
    }
}
